package com.stockz.core.model;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;

import org.hibernate.annotations.Index;
import org.springframework.context.annotation.Lazy;

@Entity
@Lazy(true)
public class Scrip implements Serializable,Comparable<Scrip> {
	private static final long serialVersionUID = -3026183528541651195L;
	
	private String code;
	private String name;
	private String exchangeCode;
	private String type;
	private String group;
	
	@Override
	public String toString() {
		return name;
	}
	
	@Override
	public boolean equals(Object o) {
		if(code != null && o != null && o instanceof Scrip){
			Scrip scrip = (Scrip)o;
			if(scrip.code != null){
				return code.trim().equalsIgnoreCase(scrip.code.trim());
			}
		}
		return super.equals(o);
	}
	
	@Override
	public int hashCode() {
		if(code != null){
			return code.hashCode();
		}
		return super.hashCode();
	}
	
	public int compareTo(Scrip o) {
		if(o != null && o.getCode() != null){
			return code.compareTo(o.getCode());
		}
		return 0;
	}
	
	@Id
	@Column
	@Index(name="scripCodeIndex")
	public String getCode() {
		return code;
	}
	public void setCode(String code) {
		this.code = code;
	}

	@Column
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	@Column
	public String getExchangeCode() {
		return exchangeCode;
	}

	public void setExchangeCode(String exchangeCode) {
		this.exchangeCode = exchangeCode;
	}
	@Column(name="scrip_type")
	@Index(name="index_scrip_type")
	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}
	@Column(name="scrip_group")
	public String getGroup() {
		return group;
	}

	public void setGroup(String group) {
		this.group = group;
	}
}
